package cn.reflection;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

/**
 * @auth wzy
 * @date 2023/9/26 15:25
 */
public class Test1 {
    public static void main(String[] args) throws ClassNotFoundException {
        // 如何获取class对象

        Person person = new Person();
        Class personClass = person.getClass();

//
//        Class c = Person.class;
//
//
//        Class aClass = Class.forName("cn.reflection.Person");
//
//
//        System.out.println(c==aClass);

        System.out.println("personClass.getName() = " + personClass.getName());
        System.out.println("personClass.getSimpleName() = " + personClass.getSimpleName());

        System.out.println("personClass.getPackage().getName() = " + personClass.getPackage().getName());


        System.out.println("personClass.getSuperclass().getName() = " + personClass.getSuperclass().getName());

        for (Class classInterface : personClass.getInterfaces()) {
            System.out.println("classInterface.getName() = " + classInterface.getName());
        }

        System.out.println("personClass.getModifiers() = " + personClass.getModifiers());
        System.out.println("Modifier.toString(personClass.getModifiers()) = " + Modifier.toString(personClass.getModifiers()));
        System.out.println("Modifier.toString(personClass.getModifiers()) = " + Modifier.toString(3));

        Constructor[] constructors = personClass.getDeclaredConstructors();
        for (Constructor constructor : constructors) {
            System.out.println("constructor.getName() = "+Modifier.toString(constructor.getModifiers()) +" "+ constructor.getName());
        }

        Field[] declaredFields = personClass.getDeclaredFields();
        for (Field field : declaredFields) {

            System.out.println("field.getName() = " + field.getType().getSimpleName()+"  "+field.getName());
        }

        Method[] methods = personClass.getDeclaredMethods();
        for (Method method : methods) {
            System.out.println("method.getName() = " + method.getName());
        }

    }
}
